<div class="ui-cover" style="display: none; position: absolute; left: 0; top: 0; z-index: 1000"></div>
<script type="text/javascript">
(function(){
	var $cover = $(".ui-cover");
	var $data = $cover.data();
	
	var contain = [];
	
	$data.resize = function(){
		$cover.width(0).height(0);
		for(var i=0; i < contain.length; i++){
			if(contain[i].resize) contain[i].resize();
		};
		$cover.width($(document).width()).height($(document).height());
	};
	
	$data.isShow = false;
	
	var execute = function(){
		var o = contain[contain.length-1];
		if(o && o.color){
			$cover.css("background-color", o.color);
		} else {
			$cover.css("background-color", "black");
		};
		
		if(o && o.opacity){
			$cover.fadeTo("fast", o.opacity);
		} else {
			$cover.fadeTo("fast", 0.5);
		};
		
		$data.resize();
		$cover.show();
		
		if(!$data.isShow){
			$(window).resize($data.resize);
			$data.isShow = true;
		};
	};
	
	$data.show = function(o){
		$(o.elem).each(function(){
			var $this = $(this);
			$this.data().ui = $.extend($this.data().ui, {cover:{}});
			if($this.css("position") != "relative" && $this.css("position") != "absolute" && $this.css("position") != "fixed"){
				console.log($this.css("position"));
				$this.data().ui.cover.position = $this.css("position");
				$this.css("position", "relative");
			};
			$this.css("z-index", 1001);
		});
		if($data.isShow){
			$(contain[contain.length-1].elem).css("z-index", contain.length);
		};
		
		contain.push(o);
		execute();
	};
	
	$data.hide = function(){
		var o = contain[contain.length-1];
		contain.pop();
		$(o.elem).each(function(){
			var $this = $(this);
			if($this.data().ui.cover.position != undefined){
				$this.css("position", $this.data().ui.cover.position);
			};
			$this.css("z-index", "auto");
		});
		
		if(contain.length == 0){
			$cover.fadeOut(0);
			$(window).die("resize", $data.resize);
			$data.isShow = false;
		} else {
			$(contain[contain.length-1].elem).css("z-index", 1001);
			execute();
		};
	};
})();
</script>